/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var binarySearch = function(nums, target) {
    nums = nums.sort((a,b)=>a-b)
    let left =0,right = nums.length
    let mid
    while(left<=right){
         mid = Math.ceil((left+right)/2)
        if(nums[mid]===target){
            return mid
        }else if(nums[mid]<target){
            left=mid+1
        }else{
            right=mid-1
        }
    }
    if(nums[mid]<target){
        return mid+1
    }else{
        return mid
    }
};

console.log(binarySearch([2, 6, 5, 1, 4, 3], 6))